= Rsync ==

; Incremental backups

To create incremental backups using hard-links courtesy of rsync's --link-dest

<pre>
rsync -rvaL --from-file rsync-list --exclude-from rsync-list-exclude ---delete --link-dest /backups/biz3/`date -d 'yesterday' +%A` biz4:/backups/biz3/ `date +%A` # day of week
rsync -rvaL --from-file rsync-list --exclude-from rsync-list-exclude ---delete --link-dest /backups/biz3/`date +%A` biz4:/backups/biz3/ `date +%B` # month
</pre>

In this case, we use date command to effectively rotate the backups during days of the week/month and months/years etc

; Logs

To move older historical dated log files as produced by PostgreSQL, Tomcat (depending on Log4J config) eg. catalina.2011-05-01 in /opt/tomcat/logs

<pre>rsync --includes **/*`date -d '2 months ago' +%Y-%m`-?? --remove-source-files /opt/tomcat/logs/ remoteuser@remote:archive/tomcat/logs
</pre>

This will move them to the remote server - don't use --delete as that applies to the destination directory where you will have other old logs already moved and you don't wish to delete those!

Obviously one needs ssh keys in authorized_keys on the remote server for rsync to use ssh from a cron job.

